package org.example.filter;


import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import jakarta.servlet.http.HttpServletRequest;

import java.io.IOException;

// 表示拦截的范围
@WebFilter(urlPatterns = "/source/*")
public class MyFilter  implements Filter {

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        Boolean logged = (Boolean) request.getSession().getAttribute("logged");
        // 登录的判断表示为空，立即结束
        if(logged==null || !logged){
            System.out.println("refuse!");
            return ;
        }
        filterChain.doFilter(servletRequest, servletResponse);
    }
}
